﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using SkeletonNET.Base.Crud.UnitOfWork;

namespace SkeletonNET.Crud.Repository
{
    /// <summary>
    /// The basic IRepository interface.
    /// </summary>
    /// <typeparam name="TEntity">The type of the entity.</typeparam>
    public interface IRepository<TEntity> : IReadonlyRepository<TEntity>, IDisposable
        where TEntity : class, IEntity, new()
    {
        /// <summary>
        /// Sets the UnitOfWork. This can be set from outside so that it is possible to share a unitofwork between different repositories.
        /// </summary>
        /// <value>
        /// The unit of work
        /// </value>
        IUnitOfWork UnitOfWork { set; }
        /// <summary>
        /// Insert an entity into the context.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns>Reference to the newly inserted entity.</returns>
        TEntity Insert(TEntity entity);
        /// <summary>
        /// Delete an existing entity.
        /// </summary>
        /// <param name="entity">The entity to delete.</param>
        void Delete(TEntity entity);
        /// <summary>
        /// Delete an entity by its id
        /// </summary>
        /// <param name="id">The id of the entity to delete.</param>
        void DeleteByID(object id);
        /// <summary>
        /// Update an existing entity.
        /// </summary>
        /// <param name="entity">The entity to update.</param>
        /// <returns>Reference to the updated entity.</returns>
        TEntity Update(TEntity entity);
        /// <summary>
        /// Save the data into the UOW
        /// </summary>
        void Save();
    }
}